import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:guochaoapp/common/widges/appbar.dart';
import 'package:guochaoapp/controller/mine/add_invoice_controller.dart';
import 'package:guochaoapp/model/invoice_entity.dart';
import 'package:guochaoapp/r.dart';

class GCAddInvoicePage extends StatelessWidget {
  GlobalKey<FormState> _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {

    GCAddInvoiceController c = Get.put(GCAddInvoiceController());

    return Scaffold(
      backgroundColor: Colors.white,
      appBar: GCAppBar(
        titleText: "发票信息管理",
        actions: [
          Row(
            children: [
              GestureDetector(
                  onTap: c.clearTap,
                  child: Text("清除", style: TextStyle(color: Colors.white)),),
              SizedBox(width: 23)
            ],
          )
        ],
      ),
      body: Obx(() => _initSubviews()),
    );
  }

  _initSubviews() {
    GCAddInvoiceController c = Get.put(GCAddInvoiceController());

    return ListView(
      children: [
        Form(
          key: _formKey,
          child: ListView.builder(
            itemCount: c.textEdittingControllers.length == 0 ? 9 : c.textEdittingControllers.length,
            shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
              itemBuilder: (context, index) {
            return _itemView(index);
          }),
        ),
        SizedBox(height: 30),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: 248,
              height: 37,
              child: RaisedButton(
                  color: Theme.of(Get.context).primaryColor,
                  onPressed: c.submitTap,
                  child: Text(
                    c.isEdit.value ? "修改" : "保存",
                    style: TextStyle(color: Colors.white),
                  )),
            ),
          ],
        )

      ],
    );
  }

  _itemView(int index) {
    GCAddInvoiceController c = Get.put(GCAddInvoiceController());

    return Container(
      height: index == 5 ? 90 : 50,
      color: Colors.white,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            children: [
              SizedBox(width: 20),
              Text(
                c.titles[index],
                style: TextStyle(color: Color(0xFF333333), fontSize: 16, fontWeight: FontWeight.bold),
              ),
              SizedBox(width: 15),
              Expanded(
                child: TextFormField(
                  controller: c.textEdittingControllers[index],
//                  initialValue: c.values.length == 0 ? "" : c.values[index],
//                          focusNode: _onefocusNode,
                  textInputAction: TextInputAction.next,
//                                      onFieldSubmitted: (v) => FocusScope.of(context).requestFocus(_passwdfocusNode),
//                          onSaved: (value) => c.values[index] = value,
//                          onChanged: (value) => c.values[index] = value,
                  decoration: InputDecoration(
                      contentPadding: EdgeInsets.only(left: 10),
                      hintText: "必填",
                      hintStyle: TextStyle(
                          fontSize: 13, color: Color(0xFFD8D8D8)),
                      enabledBorder: InputBorder.none,
                      focusedBorder: InputBorder.none
                  ),
                ),
              ),
              SizedBox(width: 10),
            ],
          ),
          Container(
            height: index == 5 ? 20 : 0,
            child: Column(
              children: [
                Container(height: 10, color: Colors.white),
                Container(height: 10, color: Color(0xFFF4F8FE)),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
